<template>
	<view style="overflow: auto;">
		<u-cell-group :border='false'>
			<u-cell-item v-if='login==0' :title="userInfo&&userInfo.name?userInfo.name:'点击登录'" :border-bottom='false'
				@click="goPage('/pages/login/login','login')">
				<u-image slot="icon" width="120rpx" height="120rpx" class='u-m-r-20' border-radius='8'
					src="/static/logo.png"></u-image>
			</u-cell-item>
			<u-cell-item v-else :title="userInfo.name" :label='"账号:"+userInfo.mobile' :border-bottom='false'
				:arrow="false">
				<u-image slot="icon" width="120rpx" height="120rpx" class='u-m-r-20' border-radius='8'
					:src="photo"></u-image>
			</u-cell-item>
			<u-gap height="20" bg-color="#f1f1f1"></u-gap>
			<u-cell-item icon="list" icon-size='40' title="我的订单" @click="goPage('/pages/shop/order/order')">
			</u-cell-item>
			<u-gap height="20" bg-color="#f1f1f1"></u-gap>
			<u-cell-item icon="map" icon-size='40' title="收货地址" @click="goPage('/pages/shop/address/address')">
			</u-cell-item>
			<u-cell-item icon="star" icon-size='40' title="喜欢的商品" @click="goPage('/pages/shop/like/like')">
			</u-cell-item>
			<u-cell-item icon="integral" icon-size='40' title="我的积分" :arrow="false"
				:value="userInfo?userInfo.score : 0"></u-cell-item>
			<u-cell-item icon="home" icon-size='40' title="我的物业" @click="goBack"></u-cell-item>
			<u-gap height="20" bg-color="#f1f1f1"></u-gap>
			<u-cell-item icon="setting" icon-size='40' @click="goPage('/pages/shop/setup/setup')" title="设置">
			</u-cell-item>
			<u-cell-item icon="download" icon-size='40' title="下载APP">
			</u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		getByMobile
	} from '@/api/index.js'
	import {
		$imgUrl
	} from '@/service/request.js'
	export default {
		name: "w-shop-mine",
		computed: {
			...mapState(['userInfo', 'login']),
			photo() {
				return $imgUrl + this.userInfo.photo
			},
		},
		data() {
			return {

			}
		},
		onShow() {
			if (this.userInfo && this.userInfo.mobile) {
				getByMobile({
					mobile: this.userInfo.mobile
				}).then(res => {
					this.$store.commit('setUserInfo', res)
				})
			}
		},
		methods: {
			goBack() {
				uni.showTabBar()
				this.$u.route({
					url: '/pages/index/index',
					type: 'tab'
				})
			},
			out() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录？',
					success: (res) => {
						if (res.confirm) {
							uni.clearStorage()
							this.$store.commit('setUserInfo', {})
							this.$store.commit('setLogin', 0)
							uni.clearStorageSync()
							this.$u.route({
								type: 'tab',
								url: '/pages/index/index'
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			goPage(path, type) {
				if (type == 'login') {
					this.$u.route('/pages/login/login')
					return
				}
				if (this.login == 0) {
					uni.showModal({
						title: '提示',
						content: '请先登录',
						success: (res) => {
							if (res.confirm) {
								this.$u.route('/pages/login/login')
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return
				}
				if (type == 'certification' && this.userInfo.idno) {
					uni.showModal({
						title: '提示',
						content: '已完成实名，是否需要更新？',
						success: (res) => {
							if (res.confirm) {
								this.$u.route(path);
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return
				}
				this.$u.route(path);
				// uni.showModal({
				// 	title: '提示',
				// 	content: '请完善信息',
				// 	success: (res) => {
				// 		if (res.confirm) {
				// 			this.goPage('/pages/mine/information/information')
				// 		} else if (res.cancel) {
				// 			console.log('用户点击取消');
				// 		}
				// 	}
				// });
			}
		}
	}
</script>

<style scoped>

</style>
